let arr = [1, 2, 3, 1];
let dp = [];
let dpnum = [];
dpnum[0] = dpnum[1] = 1;
dp[0] = arr[0];
dp[1] = Math.max(arr[0], arr[1]);
for (let i = 2; i < arr.length; i++) {
  if (dp[i - 2] + arr[i] > dp[i - 1]) {
    dpnum[i] = dpnum[i - 2] + 1;
  } else {
    dpnum[i] = dpnum[i - 1];
  }
  dp[i] = Math.max(dp[i - 2] + arr[i], dp[i - 1]);
}
console.log(dp[arr.length - 1], dpnum[arr.length - 1]);
console.log("1 2 3 4".split(" "));
